package com.prs.crm.service.stock.impl;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.stock.StoreRoomDao;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.store.StorePlace;
import com.prs.crm.domain.store.StoreRoom;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.stock.StoreRoomService;

public class StoreRoomServiceImpl extends BaseServiceImpl<StoreRoom,StoreRoomDao> implements StoreRoomService{

	@Autowired
	private PersonService personService;

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	public void save(StoreRoom room,String managerstr)
	{
		Collection<Person> managers = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(managerstr.split(",")));
		if (room.getManagers()!=null)
			room.getManagers().clear();
		for (Person manager : managers)
		{
			room.addManager(manager);
		}
		super.save(room);
	}
	
	public void saveStorePlace(StoreRoom room,StorePlace place)
	{
		room.addPlace(place);
		super.save(room);
	}
	
	public void removeStorePlace(StoreRoom room,StorePlace place)
	{
		room.removePlace(place);
		super.save(room);
	}

	@Override
	public List<StoreRoom> getAllstoreroom() {
		// TODO Auto-generated method stub
		return this.getDao().getAllStoreRoom();
	}

	@Override
	public void saveOrStoreRoom(StoreRoom room) {
		// TODO Auto-generated method stub
		this.getDao().saveOrStoreRoom(room);
	}

	@Override
	public StoreRoom getRoomBycode(String code) {
		// TODO Auto-generated method stub
		return this.getDao().getRoomBycode(code);
	}
	
}
